import numpy as np
import pandas as pd
from sklearn.preprocessing import StandardScaler
import tensorflow as tf
from joblib import load

class NN(object):
    
    def __init__(self):
        self.loaded_model = tf.keras.models.load_model('timing/my_model.keras')
        self.scaler = load('timing/scaler.joblib')
        
    def get_hourly_trend(self):
        """获取预测结果
        """
        n_steps = 7
        df_pivot = pd.read_csv('./timing/scenic_data.csv')
        #latest_data = df_pivot.iloc[-n_steps].values#取后七天数据
        x_values = df_pivot.iloc[-n_steps:]
        x_values.iloc[-1,x_values.columns.get_loc('count')] = 0
        x_lasterst = x_values.values
        latest_data = x_lasterst.reshape(1,n_steps,lasterst_data.shape[1])
        
        #预测与反归一化
        predict = self.loaded_model.predict(latest_data)
        predict_counts = self.scaler.inverse_transform(predict)#反归一化
        predict_counts[predict_counts < 0] = 0#修正负数
        
        hourly_trend = predict_counts[0].astype(int).tolist()
        print(hourly_trend)
        
if __name__ == '__main__':
    nn = NN()
    nn.get_hourly_trend()
